
<%@ page language="java" contentType="text/html;charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE HTML>
<html>

<head>
    <title>角色编辑</title>
</head>
<body >
<div style="width:500px;height:472px">
    <div id="tabs" class="easyui-tabs" style="width:99.9%;height:99%;padding-left: 1px;padiing-right: 1px">
        <div title="基本信息">
            <div class="row cl" style="text-align:right;height:400px">
                <div class="col-9 col-offset-3">
                    <form id='registerform'action="<%=request.getContextPath()%>/back/role/doupdate.do" method="post" class="form form-horizontal">
                        <input type="hidden" id="unid"name="unid" value="${role.unid}" />
                        <input type="hidden" id="createby"name="createby" value="${role.createby}" />
                        <div class="row cl">
                            <label class="form-label col-3"><span class="c-red">*</span>角色名称：</label>
                            <div class="formControls col-5">
                                <input type="text" class="input-text" value="${role.rolename}" id="rolename" name="rolename" datatype="*3-12">
                            </div>
                            <div class="col-4"> </div>
                        </div>
                        <div class="row cl">
                            <label class="form-label col-3">创建时间：</label>
                            <div class="formControls col-5">
                                <input  ignore="ignore"  value="${role.createdate}" id="createdate" name='createdate'class="Wdate input-text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'%y-%M-%d'})" />
                            </div>
                            <div class="col-3"> </div>
                        </div>
                        <%--<div class="row cl" style="margin-top:25px">--%>
                            <%--<div class="col-9 col-offset-3">--%>

                                <%--<button class="btn btn-primary radius" id="submitBtn"> 保存</button>--%>
                                <%--&nbsp;&nbsp;&nbsp;--%>
                                <%--&lt;%&ndash;<button class="btn  radius" onclick="close()"> 关闭</button>&ndash;%&gt;--%>
                                <%--&lt;%&ndash;&nbsp;&nbsp;&nbsp;&ndash;%&gt;--%>
                            <%--</div>--%>
                        <%--</div>--%>
                    </form>
                </div>
            </div>
            <div class="row cl" style="text-align:right;height:60px">
                <div class="col-9 col-offset-3">

                    <button class="btn btn-primary radius" id="submitBtn"> 保存</button>&nbsp;&nbsp;&nbsp;
                    <%--<button class="btn  radius smallBtn"> 取消</button>&nbsp;&nbsp;&nbsp;--%>
                </div>
            </div>
        </div>

        <div title="权限编辑">
            <div class="row cl" style="text-align:right;height:400px">
                <div class="zTreeDemoBackground left">
                    <ul id="role_menutree" class="ztree"></ul>
                </div>
            </div>
            <div class="row cl" style="text-align:right;height:60px">
                    <button class="btn btn-primary radius smallBtn" id="menulinkBtn" onclick="menuLink()" > 授权</button>&nbsp;&nbsp;&nbsp;
                    <%--<button class="btn  radius smallBtn"> 取消</button>&nbsp;&nbsp;&nbsp;--%>
            </div>
        </div>
    </div>

</div>
<<<<<<< .mine

</body>
</html>
<%@include file="../../head-ui.jsp"%>

<script type="text/javascript">

    var treeObj;
    var code;
    var setting = {
        check: {
            enable: true
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        callback:{
        }
    };
    function setCheck() {
        var py = $("#py").attr("checked")? "p":"",
                sy = $("#sy").attr("checked")? "s":"",
                pn = $("#pn").attr("checked")? "p":"",
                sn = $("#sn").attr("checked")? "s":"",
                type = { "Y":py + sy, "N":pn + sn};
        treeObj.expandAll(true);
//        zTree.setting.check.chkboxType = type;
//        showCode('setting.check.chkboxType = { "Y" : "' + type.Y + '", "N" : "' + type.N + '" };');
        treeObj.setting.check.chkboxType = { "Y" : "ps", "N" : "s" };
        showCode('setting.check.chkboxType = { "Y" : "ps", "N" : "ps" };');
    }
    function showCode(str) {
        if (!code) code = $("#code");
        code.empty();
        code.append("<li>"+str+"</li>");
    }
    function menuLink(){
        var nodes = treeObj.getCheckedNodes(true);
        var unids=new Array();
        for(var i=0;i<nodes.length;i++){
            unids.push(nodes[i].id)
        }
        var parm=unids.join(",");
        $.post( $("#contextPath").val()+"/back/role/domenulink.do", {menuunids:parm,roleunid:'${role.unid}',enable:'1'}, function(res){
            if(res.success==true){
//                doSearch();
                layer.msg('授权成功!',{icon: 1,time:1000});
            }else{
                layer.msg('授权失败!',{icon: 1,time:1000});
            }

        })
    }
    $.ajax({
        type: 'Get',
        url: '<%=request.getContextPath()%>/back/role/menutree.do?roleunid=${role.unid}',
        dataType: "json", //可以是text，如果用text，返回的结果为字符串；如果需要json格式的，可是设置为json
        success: function (data) {
            treeObj=$.fn.zTree.init($("#role_menutree"), setting, data.data);
            setCheck();
            $("#py").bind("change", setCheck);
            $("#sy").bind("change", setCheck);
            $("#pn").bind("change", setCheck);
            $("#sn").bind("change", setCheck);
        },
        error: function (msg) {
            layer.alert(" 数据加载失败！");
        }
    });
    $(function(){

        var form = $("#registerform").Validform({
            tiptype: 3,
            callback: function (data) {

                if (data.message == "false") {
                    layer.msg('保存失败!', {icon: 1, time: 1000});

                } else {
                    layer.alert('保存成功!', {
                        icon: 1,//2表示保存失败图标，1表示保存成功
                        closeBtn: false,
                        shadeClose: true,
                        title: "提示"
                    }, function () {
                        layer_close();
                    });
                    //layer.msg('保存成功!',{icon: 1,time:1000});
                }
            },
            ajaxPost: true,
            showAllError: true

        });

        $("#submitBtn").click(function () {
            form.submitForm(false);
        })

    });

</script>

